<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/5/13
  Time: 15:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //获取项目的根路径
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <meta charset="utf-8">
    <title>医生增删改查页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=basePath%>drug/css/drugSelect.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>swee/sweetalert.css">
    <script type="text/javascript" src="<%=basePath%>swee/sweetalert-dev.js"></script>
    <script src="<%=basePath%>jquery/jquery-1.12.4.js"></script>
    <style>
        #yingchang{
            width: 500px;
            height: 510px;
            background-color: white;
            opacity: 0.9;
            border-radius: 5%;
            border: 1px solid  rgb(70, 200, 200);
            position: absolute;
            top: 10%;
            left:30%;
        }
        #yingchang2{
            width: 500px;
            height: 510px;
            background-color: white;
            opacity: 0.9;
            border-radius: 5%;
            border: 1px solid  rgb(70, 200, 200);
            position: absolute;
            top: 10%;
            left: 30%;
        }
        .newinput{
            margin-top: 10px;
            border: none;
            border-bottom:1.5px solid #009f95;
            margin-left: 10px;
            height: 30px;
        }
        .ppp{
            margin-top: 20px;
            margin-left: 30px;
            /*border: 1px solid red;*/
            margin-left: 80px;
            width: 430px;
            height: 500px;
        }
    </style>
</head>
<body>
<div id="head" style="height: 600px">
    <ul>
        <li style="width: 100%;  ">
            <div class="head_below1" style="width: 100%;margin-top: 30px">
                <h2 style="font-size: 40px">华子医院人员管理页面</h2>
                <form action="<%=basePath%>DoctorServlett" method="post" style="margin-left: 300px">
                    <p>请输入姓名:<input type="text" name="stayDrug" placeholder="请输入" class="input1">
                        <%--                        &nbsp; &nbsp; &nbsp; 诊疗卡号: <input type="text" name="cardNumber" placeholder="请输入诊疗卡号" class="input2">--%>
                        <button type="submit" class="layui-btn" style="margin-left: 20px">查询</button>
                        <span style="color: #009f95;font-size: 25px;font-weight: bold;margin-left: 100px">点我新增--></span><button type="button" class="layui-btn" id="xingzeng">新增医生</button>
                    </p>
                </form>
                <%--                存放查询结果--%>
                <div class="layui-form" style="margin-top: 20px">
                    <table class="layui-table" style="font-size: 10px">
                        <thead>
                        <tr>
                            <td>编号</td>
                            <td>姓名</td>
                            <td>性别</td>
                            <td>年龄</td>
                            <td>所属科种</td>
                            <td>身份证号</td>
                            <td>电话</td>
                            <td>级别</td>
                            <td>所属科室</td>
                            <td>毕业学校</td>
                            <td>入职日期</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                            <c:forEach items="${requestScope.pageList2.list}" var="doctor">
                                <tr>
                                    <td>${doctor.doctorId}</td>
                                    <td>${doctor.doctorname}</td>
                                    <td>${doctor.doctorSex}</td>
                                    <td>${doctor.doctorAge}</td>
                                    <td>${doctor.doctorke}</td>
                                    <td>${doctor.doctorcard}</td>
                                    <td>${doctor.doctorphone}</td>
                                    <td>${doctor.position}</td>
                                    <td>${doctor.type}</td>
                                    <td>${doctor.doctorType}</td>
                                    <td>${doctor.doctorDate}</td>
                                    <td>
                                        <span><button type="button"  class="layui-btn">编辑</button></span>
                                        <label><button type="button"  class="layui-btn">删除</button></label>
                                    </td>
                                </tr>
                            </c:forEach>
                        </tbody>
                    </table>
                    <p style="text-align: center">
                        <c:choose>
                        <c:when test="${requestScope.pageList2.list.size()>0}">
                        <c:if test="${requestScope.pageList2.currentPage>1}">
                        <a href="<%=basePath%>DoctorServlett?currentPage=${requestScope.pageList2.currentPage-1}&names=${requestScope.names}">上一页</a>
                        </c:if>
                            ${requestScope.pageList2.currentPage}/${requestScope.pageList2.totalPage}
                        <c:if test="${requestScope.pageList2.currentPage<requestScope.pageList2.totalPage}">
                        <a href="<%=basePath%>DoctorServlett?currentPage=${requestScope.pageList2.currentPage+1}&names=${requestScope.names}">下一页</a>
                        </c:if>
                        </c:when>
                        <c:otherwise>
                    <h2 style="text-align: center">没找到您需要的信息！</h2>
                    </c:otherwise>
                    </c:choose>
                    </p>
                </div>
            </div>
        </li>
    </ul>
</div>
<div id="yingchang" style="display: none">
    <form>
        <p id="biaoti" style="color: #009f95;font-weight: bold;font-size: 30px;margin-top: 10px;margin-left: 105px">华子医院医生新增页面 <img
                src="<%=basePath%>/drug/image/cuowu.png" style="width: 30px;margin-left: 30px" class="imgcilck"> </p>
        <div class="inputTijiao" style="font-family: 微软雅黑">
            <p>姓&nbsp;  &nbsp; &nbsp; 名：<input type="text" value="" placeholder="请输入姓名" class="input1" style="width: 200px;" id="name"></p>
            <p style="margin-top: 10px">
                性&nbsp;  &nbsp; &nbsp; 别：<input type="radio" value="男" class="sex" name="sex" checked="checked">男<input type="radio" value="女" name="sex" class="sex" style="margin-left:20px">女
                &nbsp;  &nbsp; &nbsp;  &nbsp;  &nbsp;  &nbsp;年&nbsp;  &nbsp; &nbsp; 龄:<input type="text" value="" placeholder="年龄" id="age" class="input1" style="width: 50px">
            </p>
            <p style="margin-top: 10px">
               所属科种
                <select name="interest1"  class="input1" id="kezhong">
                    <option value="内科" selected="selected">内科</option>
                    <option value="外科" >外科</option>
                </select>
                &nbsp;  &nbsp; &nbsp;  &nbsp;  &nbsp;  &nbsp; 所属科室
                <select name="interest2"  class="input1" id="keshi">
                    <option value="神经外科">神经外科</option>
                    <option value="骨科">骨科</option>
                    <option value="华子科">华子科</option>
                </select>
            </p>
            <p>
               电&nbsp;  &nbsp; &nbsp; 话: <input type="text" value="" placeholder="请输入电话" id="phone" class="input1" style="width: 200px;">
            </p>
            <p>
                身份证号:<input type="text" value="" id="shengfeng" placeholder="请输入身份证号" class="input1" style="width: 250px;">
            </p>
            <p style="margin-top: 10px">
                级&nbsp;  &nbsp; &nbsp;&nbsp;别:
                <select name="interest3" style="width: 150px"  class="input1" id="jibie">
                <option value="主治医师">主治医师</option>
                <option value="主任医生">主任医生</option>
                <option value="金牌性感医生">金牌性感医生</option>
                    <option value="神医">神医</option>
            </select>
            </p>
            <p style="margin-top: 10px">
                毕业学校:<input type="text" value="" id="school" placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p>
                入职日期:<input type="date" value="" id="dateRiqi"  placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p style="margin-top: 15px;margin-left: 170px">
                <button type="button" class="layui-btn" id="quxiao">取消</button>
                <button type="button" class="layui-btn" id="queren" style="margin-left: 40px">确认</button>
            </p>
        </div>
    </form>
</div>

<div id="yingchang2" style="display: none">
    <form>
        <p id="biaoti2" style="color: #009f95;font-weight: bold;font-size: 30px;margin-top: 10px;margin-left: 105px">华子医院医生修改页面 <img
                src="<%=basePath%>/drug/image/cuowu.png" style="width: 30px;margin-left: 30px" class="imgcilck2"> </p>
        <div class="inputTijiao" style="font-family: 微软雅黑">
            <p>姓&nbsp;  &nbsp; &nbsp; 名：<input type="text" value="" placeholder="请输入姓名" class="input1" style="width: 200px;" id="name2"></p>
            <p style="margin-top: 10px">
                性&nbsp;  &nbsp; &nbsp; 别：<input type="radio" value="男" class="sex" name="sex" checked="checked">男<input type="radio" value="女" name="sex" class="sex" style="margin-left:20px">女
                &nbsp;  &nbsp; &nbsp;  &nbsp;  &nbsp;  &nbsp;年&nbsp;  &nbsp; &nbsp; 龄:<input type="text" value="" placeholder="年龄" id="age2" class="input1" style="width: 50px">
            </p>
            <p style="margin-top: 10px">
                所属科种
                <select name="interest1"  class="input1" id="kezhong2">
                    <option value="内科" selected="selected">内科</option>
                    <option value="外科" >外科</option>
                </select>
                &nbsp;  &nbsp; &nbsp;  &nbsp;  &nbsp;  &nbsp; 所属科室
                <select name="interest2"  class="input1" id="keshi2">
                    <option value="神经外科">神经外科</option>
                    <option value="骨科">骨科</option>
                    <option value="华子科">华子科</option>
                </select>
            </p>
            <p>
                电&nbsp;  &nbsp; &nbsp; 话: <input type="text" value="" placeholder="请输入电话" id="phone2" class="input1" style="width: 200px;">
            </p>
            <p>
                身份证号:<input type="text" value="" id="shengfeng2" placeholder="请输入身份证号" class="input1" style="width: 250px;">
            </p>
            <p style="margin-top: 10px">
                级&nbsp;  &nbsp; &nbsp;&nbsp;别:
                <select name="interest3" style="width: 150px"  class="input1" id="jibie2">
                    <option value="主治医师">主治医师</option>
                    <option value="主任医生">主任医生</option>
                    <option value="金牌性感医生">金牌性感医生</option>
                    <option value="神医">神医</option>
                </select>
            </p>
            <p style="margin-top: 10px">
                毕业学校:<input type="text" value="" id="school2" placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p>
                入职日期:<input type="date" value="" id="dateRiqi2"  placeholder="请输入" class="input1" style="width: 200px;">
            </p>
            <p style="margin-top: 15px;margin-left: 170px">
                <button type="button" class="layui-btn" id="quxiao2">取消</button>
                <button type="button" class="layui-btn" id="queren2" style="margin-left: 40px">确认</button>
            </p>
        </div>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    let array=new Array();
    let array2=new Array(11);
    let array3=new Array();
    $(document).ready(function () {
        $("#yingchang").hide();
        $("#yingchang2").hide();
        $("#xingzeng").click(function () {
            $("#yingchang").show();
            qingkong();
            $(".inputTijiao").addClass("ppp");
            $(".input1").addClass("newinput");
        });

        $(".imgcilck").click(function () {
            $("#yingchang").hide();
        });
        $(".imgcilck2").click(function () {
            $("#yingchang2").hide();
        });
        $("#quxiao").click(function () {
            $("#yingchang").hide();
        });
        $("#quxiao2").click(function () {
            $("#yingchang2").hide();
        });

        //更新
        $("tbody tr td span").click(function () {
            $("#yingchang2").show();
            $(".inputTijiao").addClass("ppp");
            $(".input1").addClass("newinput");
            let count=0;
            $(this).parent().parent().children("td").each(function () {
                 array2[count]=$(this).text();
                 count++;
             });
             $("#name2").val(array2[1]);
             // alert(array2[2]);
            //动态设置单选框的选中
             if(array2[2]=="男"){
                 // alert(array2[2])
                 $("#yingchang2 input[name='sex']:eq(0)").prop("checked",true);
                 $("#yingchang2 input[name='sex']:eq(1)").prop("checked",false);
                 // $(".sex:radio:checked").val("");
             }else {
                 $("#yingchang2 input[name='sex']:eq(0)").prop("checked",false);
                 $("#yingchang2 input[name='sex']:eq(1)").prop("checked",true);
             }

             $("#age2").val(array2[3]);
             $("#kezhong2").val(array2[4]);
             $("#shengfeng2").val(array2[5]);
             $("#phone2").val(array2[6]);
             $("#jibie2").val(array2[7]);
             $("#keshi2").val(array2[8]);
             $("#school2").val(array2[9]);
             $("#dateRiqi2").val(array2[10]);
        })
        //删除
        $("tbody tr td label").click(function () {
            let id=$(this).parent().parent().children("td:first").text();
            swal({
                    title: "确定删除吗？",
                    text: "删除后此记录将不存在！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定删除！",
                    cancelButtonText: "取消删除！",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                        $.ajax({
                            url:"<%=basePath%>/DoctorServlett?caozuo=delete",
                            type:"POST",
                            data:{
                                id2:id
                            },dataType:"json",
                            success:function (data) {
                                if(data){
                                    swal("删除成功！");
                                    location.reload();
                                }else {
                                    swal("数据跑丢了！");
                                }
                            }
                        });
                    } else {
                        swal("您选择了取消！"," ","error");
                    }
                });

        })
        //更新确认
        $("#queren2").click(function () {
            array3[0]=$("#name2").val(); //姓名
            array3[1]=$("#yingchang2 .sex:radio:checked").val();   //性别
            array3[2]=$("#age2").val(); //年龄
            array3[3]=$("#kezhong2 option:selected").val(); //所属科种
            array3[4]=$("#shengfeng2").val(); //身份证号
            array3[5]=$("#phone2").val();  //身份证号
            array3[6]=$("#jibie2 option:selected").val(); //级别
            array3[7]=$("#keshi2 option:selected").val(); //所属科室
            array3[8]=$("#school2").val();
            array3[9]=$("#dateRiqi2").val();
            if(pangduan2()){
                swal({
                        title: "确定更新吗？",
                        text: "此记录将被修改！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定！",
                        cancelButtonText: "取消！",
                        closeOnConfirm: false,
                        closeOnCancel: false
                    },
                    function(isConfirm){
                        if(isConfirm){
                            let str3=array3.join(",");
                            $.ajax({
                                url:"<%=basePath%>/DoctorServlett?caozuo=xiugai",
                                type:"POST",
                                data:{
                                    idd:array2[0],
                                    str33:str3
                                },dataType:"json",
                                success:function (data) {
                                    if(data){
                                        swal("更新成功");
                                        $("#yingchang2").hide();
                                        location.reload();
                                    }else {
                                        swal("数据飘走了")
                                    }
                                }
                            });
                        }else {
                            swal("数据飘走了!")
                        }
                    });

            }

        });
        //插入
        $("#queren").click(function () {
            array[0]=$("#name").val(); //姓名
            array[1]=$("#yingchang .sex:radio:checked").val();   //性别
            array[2]=$("#age").val(); //年龄
            array[3]=$("#kezhong option:selected").val(); //所属科种
            array[4]=$("#shengfeng").val(); //身份证号
            array[5]=$("#phone").val();  //身份证号
            array[6]=$("#jibie option:selected").val(); //级别
            array[7]=$("#keshi option:selected").val(); //所属科室
            array[8]=$("#school").val();
            array[9]=$("#dateRiqi").val();
            if(pangduan()){
                let s = array.join(",");
               $.ajax({
                   url:"<%=basePath%>/DoctorServlett?caozuo=xinzeng",
                   type:"POST",
                   data:{
                       array1:s
                   },dataType:"json",
                   success:function (data) {
                        if(data){
                            swal("新增成功!");
                            $("#yingchang").hide();
                            location.reload();
                        }else {
                            swal("数据跑丢了！");
                            $("#yingchang").hide();
                        }
                   }
               });
            }
        });
    });

    //非空判断函数
    function pangduan() {
        if(array[0].toString().trim().length==0){
            swal("姓名不能为空!");
            return false;
        }else if(isNaN(array[2]) || array[2].toString().trim().length==0){
            swal("年龄格式错误");
            return false;
        } else if(array[4].toString().trim().length!=18){
            swal("身份证号不能小于18位");
            return false;
        }else if( array[5].toString().trim().length!=11){
            swal("电话格式不正确");
            return false;
        }else if(array[8].toString().trim().length==0){
            swal("请填写毕业学校!");
            return false;
        }else if(array[9].toString().trim().length==0){
            swal("请填写日期!");
            return false;
        }else {
            return true
        }
    }

    //非空判断函数
    function pangduan2() {
        if(array3[0].toString().trim().length==0){
            swal("姓名不能为空!");
            return false;
        }else if(isNaN(array3[2]) || array3[2].toString().trim().length==0){
            swal("年龄格式错误");
            return false;
        } else if(array3[4].toString().trim().length!=18){
            swal("身份证号不能小于18位");
            return false;
        }else if( array3[5].toString().trim().length!=11){
            swal("电话格式不正确");
            return false;
        }else if(array3[8].toString().trim().length==0){
            swal("请填写毕业学校!");
            return false;
        }else if(array3[9].toString().trim().length==0){
            swal("请填写日期!");
            return false;
        }else {
            return true
        }
    }

    function qingkong(){
        $("#name").val(""); //姓名
        $(".sex:radio:checked").val("");   //性别
        $("#age").val(""); //年龄
        $("#shengfeng").val(""); //身份证号
        $("#phone").val("");  //身份证号
        $("#school").val("");
        $("#dateRiqi").val("");
    }
</script>
